import QtQuick 1.0
import meegim 1.0


DialogLiquid {
    id: dlgMyStatus

    signal myStatusChange
    property variant myStatusSet
    property string myTextStatus//: main.statText

    hideTo: hideToLeft

    function setStatus( status, textStatus )
    {
        var resSet = false
        for( var k=0; k<modelListStat.count; k++)
        {
            var ss = dlgMyStatus.status( modelListStat.get(k).name )
            if(  ss == status ) {
                listViewStatus.currentIndex = k
                wrapperTextEdit.text = textStatus
                resSet = true
                break;
            }
        }
        return resSet
    }

    width: parent.width*0.9
    height: parent.height*0.58

    ListModel {
        id: modelListStat
        ListElement {
            name: "online"
            image: "qrc:/qml/images/presence-online.png"
        }
        ListElement {
            name: "chat"
            image: "qrc:/qml/images/presence-online.png"
        }
        ListElement {
            name: "away"
            image: "qrc:/qml/images/presence-away.png"
        }
        ListElement {
            name: "XA"
            image: "qrc:/qml/images/presence-away.png"
        }
        ListElement {
            name: "DND"
            image: "qrc:/qml/images/presence-busy.png"
        }
        ListElement {
            name: "offline"
            image: "qrc:/qml/images/presence-offline.png"
        }
    }

    function status( nameElement )
    {
        var ret = ""
        if( nameElement === "online" ) {
            ret = XmppClient.Online
        } else if( nameElement === "chat" ) {
            ret = XmppClient.Chat
        } else if( nameElement === "away" ) {
            ret = XmppClient.Away
        } else if( nameElement === "XA" ) {
            ret = XmppClient.XA
        } else if( nameElement === "DND" ) {
            ret = XmppClient.DND
        } else if( nameElement === "offline" ) {
            ret = XmppClient.Offline
        }
        return ret
    }

    function textItem( nameElement )
    {
        var ret = ""
        if( nameElement === "online" ) {
            ret = qsTr("Available")
        } else if( nameElement === "chat" ) {
            ret = qsTr("Chatty")
        } else if( nameElement === "away" ) {
            ret = qsTr("Away")
        } else if( nameElement === "XA" ) {
            ret = qsTr("Extended away")
        } else if( nameElement === "DND" ) {
            ret = qsTr("Do not disturb")
        } else if( nameElement === "offline" ) {
            ret = qsTr("Offline")
        }
        return ret
    }

    Component {
        id: componentWrapper
        Rectangle {
            id: wrapper
            width: listViewStatus.width
            height: 70
            //border.color: "gray"
            gradient: gr_free
            Image {
                id: imgStatus
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left
                anchors.leftMargin: 20
                source: image
                height: 56; width: height
                smooth: true
            }
            Text {
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: imgStatus.right
                anchors.leftMargin: 20
                id: txtStatus
                text: textItem( name )
                font.pixelSize: 28
            }
            Gradient {
                id: gr_free
                GradientStop { id: gr1; position: 0; color: "white" }
                GradientStop { id: gr2; position: 0.5; color: "#ededed" }
                GradientStop { id: gr3; position: 1; color: "#d7d7d7" }
            }
            Gradient {
                id: gr_press
                GradientStop { position: 0; color: "lightblue" }
                GradientStop { position: 1; color: "lightblue" }
                GradientStop { position: 0.5; color: "#ededed" }
            }
            MouseArea {
                id: mouseAreaItem;
                anchors.fill: parent
                onClicked: {
                    wrapper.ListView.view.currentIndex = index
                    dlgMyStatus.myStatusSet = status( name )
                    dlgMyStatus.myTextStatus = wrapperTextEdit.text
                    dlgMyStatus.myStatusChange()
                    dlgMyStatus.state = "hidden"
                }
            }

            states: State {
                name: "Current"
                when: wrapper.ListView.isCurrentItem
                //PropertyChanges { target: wrapper; color: "lightblue" }
                PropertyChanges { target: wrapper; gradient: gr_press }
                PropertyChanges { target: imgStatus; anchors.leftMargin: 30 }
            }
        }
    }

    property int __marg1 : 3
    ListView {
        id: listViewStatus
        anchors.top: parent.top
        anchors.topMargin: __marg1
        anchors.left: parent.left
        anchors.leftMargin: __marg1
        anchors.bottom: wrapperTextEdit.top
        anchors.bottomMargin: 10
        width: parent.width - 2*__marg1
        model: modelListStat
        delegate: componentWrapper
        clip: true
    }

    MyTextInput2 {
        id: wrapperTextEdit
        height: 55
        anchors.bottom: parent.bottom; anchors.bottomMargin: 5
        anchors.left: parent.left; anchors.leftMargin: 10
        anchors.right: parent.right; anchors.rightMargin: 10
        text: dlgMyStatus.myTextStatus
        placeholderText: qsTr("Status text")
    }


}
